import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoDialogActionDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => CupertinoDialogActionState();
}

class CupertinoDialogActionState extends State<CupertinoDialogActionDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('CupertinoDialogAction'),
        centerTitle: true,
      ),
      body: Center(
        child: CupertinoButton(
          child: Text('点击弹窗'),
          onPressed: (){
            showDialog(context: context, builder: (context){
              return _cupertinoAlertDialogForCustom(context);
            });
          },
        )
      ),
    );
  }

  /**
   * 一个按钮的普通Dialog
   */
  CupertinoAlertDialog _cupertinoAlertDialogForCustom(context) {
    return CupertinoAlertDialog(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(Icons.add_alert),
          Padding(padding: EdgeInsets.all(10)),
          Text('Alert')
        ],
      ),
      content: Column(
        children: [
          Padding(padding: EdgeInsets.all(15)),
          Container(
            height: 30,
            width: 30,
            child: Image.network(
                'http://tiebapic.baidu.com/forum/w%3D580/sign=a96ca741eafaaf5184e381b7bc5594ed/7ea6a61ea8d3fd1f2643ad5d274e251f95ca5f38.jpg'),
          ),
          Padding(padding: EdgeInsets.all(15)),
          Text('这是一个简单的图文弹窗')
        ],
      ),
      actions: [
        CupertinoDialogAction(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [Icon(Icons.arrow_forward), Text('我知道了')],
          ),
          textStyle: TextStyle(
              fontSize: 20, fontWeight: FontWeight.bold, color: Colors.blue),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoDialogAction(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [Icon(Icons.arrow_forward), Text('确认')],
          ),
          textStyle: TextStyle(
              fontSize: 20, fontWeight: FontWeight.bold, color: Colors.blue),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoDialogAction(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [Icon(Icons.arrow_forward), Text('取消')],
          ),
          textStyle: TextStyle(
              fontSize: 20, fontWeight: FontWeight.bold, color: Colors.grey),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ],
    );
  }
}
